<?php

namespace app\common\lib;

use think\facade\Cache;
class Redis{
	private static $config= [
		"sms" => [
			'name' => '手机短信key',
			'prefix'=>'sms_',
			'expire'=> 300,
		],
		"user" => [
			'name' => '用户',
			'prefix'=>'user_',
			'expire'=> 600,
		],
		"live_user" => [
			'name' => '用户',
			'prefix'=>'live_user',
			'expire'=> 0,
		],
		"seo" => [
			'name' => '网站SEO',
			'prefix'=>'seo_',
			'expire'=> 3600,
		],
	];




	public static function set($key, $id = '', $value = ''){
		if (!array_key_exists($key, self::$config)) {
			return null;
		}
		$config = self::$config[$key];
		$cacheKey = $config['prefix'] . $id;
		return Cache::set( $cacheKey ,$value,$config['expire']);
	}

	public static function Sadd($key, $value = ''){
		if (!array_key_exists($key, self::$config)) {
			return null;
		}
		$config = self::$config[$key];
		$cacheKey = $config['prefix'];
		//echo $cacheKey;die;

		return Cache::Sadd($cacheKey, $value);
	}

	public static function Srem($key, $value = ''){
		if (!array_key_exists($key, self::$config)) {
			return null;
		}
		$config = self::$config[$key];
		$cacheKey = $config['prefix'];
		return Cache::Srem($cacheKey, $value);
	}

	public static function Smembers($key){
		if (!array_key_exists($key, self::$config)) {
			return null;
		}
		$config = self::$config[$key];
		$cacheKey = $config['prefix'];
		return Cache::Smembers($cacheKey);
	}


	public static function get($key, $id = ''){
		if (!array_key_exists($key, self::$config)) {
			return null;
		}
		$config = self::$config[$key];
		$cacheKey = $config['prefix'] . $id;
		return Cache::get($cacheKey);
	}
}
